import time
from datetime import datetime
import uuid

from sqlalchemy.dialects.postgresql import Any

from config.database import Base
from sqlalchemy import Column, Integer, String, TIMESTAMP, Boolean


def gen_uuid():
    timestamp = str(int(time.time()))

    return uuid.uuid5(uuid.NAMESPACE_DNS, str(timestamp) + str(uuid.uuid4()))


class GroupModel(Base):
    """
    分类分组表
    """
    __tablename__ = 'tb_groups'
    __table_args__ = {
        'schema': 'reviews'
    }

    group_id = Column(String(32), default=gen_uuid(), primary_key=True, comment='表索引主键')
    group_name = Column(String(10), nullable=False, comment='分类名称')
    group_code = Column(Integer, nullable=False, comment='分类代码')
    group_level = Column(Integer, default=1, comment='分类级别')
    group_thumbnail = Column(String(255), comment='分类示例图')
    parent_code = Column(Integer, default=0, comment='父节点代码')
    is_used = Column(Boolean, default=True, comment='是否启用(true启用/false停用)')
    hav_children = Column(Boolean, default=False, comment='是否有子节点')

    def __init__(self, **kw: Any):
        super().__init__(**kw)
        self.user_id = gen_uuid()
